<template>
  <div class="login" clearfix>
    <div class="login-wrap">
      <el-row type="flex" justify="center">
        <el-form ref="loginForm" :model="user" :rules="rules" status-icon label-width="80px">
          <h3>登录</h3>
          <hr>
          <el-form-item prop="username" label="用户名">
            <el-input v-model="user.username" placeholder="请输入用户名" prefix-icon></el-input>
          </el-form-item>
          <el-form-item id="password" prop="password" label="密码">
            <el-input v-model="user.password" show-password placeholder="请输入密码"></el-input>
          </el-form-item>
          <router-link to="/">找回密码</router-link>
          <router-link to="/register">注册账号</router-link>
          <el-form-item>
            <el-button type="primary" icon="el-icon-upload" @click="doLogin()">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-row>
    </div>
  </div>
</template>
 
<script>
import {request} from "../utils/request"
import qs from 'qs'
export default {
  name: "login",
  data() {
    return {
      user: {
        username: "",
        password: ""
      },
      admin:''
    };
  },
  created() {},
  methods: {
    doLogin() {
        // this.$store.state.username="467241156"
        // this.$store.state.islogin='true'
      if (!this.user.username) {
        this.$message.error("请输入用户名！");
        return;
      } else if (!this.user.password) {
        this.$message.error("请输入密码！");
        return;
      } else {
        //校验用户名和密码是否正确;
        // this.$router.push({ path: "/personal" });
        this.$ajax
          .post("http://localhost:8080/system/yesapiOneUsers/userlogin", {
            username: this.user.username,
            yesapiOneUsersPassword: this.user.password
          })
          .then(res => {
            // console.log("输出response.data.status", res.data.status);
            // if (res.data==1) {

            //   this.$ajax.post("http://localhost:8080/system/yesapiOneUsers/getuser",{
            //     username: this.user.username,
            //     yesapiOneUsersPassword: this.user.password
            //   }).then(res=>{
            //   this.$store.state.username=res.data[0].username;
            //   this.$store.state.email=res.data[0].email;
            //   this.$store.state.islogin=true;
            //   })
            //   this.$router.push({ path: "/personinfo" });
            // } else {
            //   alert("您输入的用户名或密码错误！");
            // }
            // console.log(res);
            if(res.data!=null)
            {
            localStorage.setItem('access-admin',JSON.stringify(res.data));
            localStorage.setItem('isviewnickname',false);
            // console.log(window.localStorage.getItem('access-admin'));
            // console.log(JSON.parse(window.localStorage.getItem('access-admin')));
            this.admin=JSON.parse(window.localStorage.getItem('access-admin'));
            // console.log(this.admin.nickname);
            this.$store.state.username=this.admin.nickname;
            this.$store.state.email=this.admin.email;
            this.$router.push('/home');
            // console.log(this.admin.accessToken);
            }
          });
      }
    },
  },
      mounted() {
      //this.getNetworkData();
      localStorage.setItem("token", "")
    },
};
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.login {
  width: 100%;
  height: 740px;
  background-size: cover;
  overflow: hidden;
}
.login-wrap {
  background-size: cover;
  width: 400px;
  height: 300px;
  margin: 215px auto;
  overflow: hidden;
  padding-top: 10px;
  line-height: 40px;
}
#password {
  margin-bottom: 5px;
}
h3 {
  color: #0babeab8;
  font-size: 24px;
}
hr {
  background-color: #444;
  margin: 20px auto;
}
a {
  text-decoration: none;
  color: #aaa;
  font-size: 15px;
}
a:hover {
  color: coral;
}
.el-button {
  width: 80%;
  margin-left: -50px;
}
</style>